import request from '@/utils/request'
import request2 from '@/utils/request2'
function objectToFormData(obj) {
  const formData = new FormData()
  for (const key in obj) {
    if (obj.hasOwnProperty(key)) {
      formData.append(key, obj[key])
    }
  }
  return formData
}
// 生成标题
export function gjc(data) {
  data = objectToFormData(data)
  return request({
    url: '/gjc',
    method: 'post',
    data
  })
}
// 获取文章列表
export function getwzlist(data) {
  data = objectToFormData(data)
  return request({
    url: '/getwzlist',
    method: 'post',
    data
  })
}
// 生成文章
export function getwz(data) {
  // data = objectToFormData(data)
  return request({
    url: '/getwz',
    method: 'post',
    data
  })
}
// 生成文章
export function fb(data) {
  data = objectToFormData(data)
  return request({
    url: '/fb',
    method: 'post',
    data
  })
}
// 发布文章
// export function autoSend(data) {
//   return request2({
//     url: '/api/autoSend',
//     method: 'post',
//     params: data,
//     baseURL: 'http://127.0.0.1:28089'
//   })
// }
// 代理
export function autoSend(data) {
  return request2({
    url: '/autoSend',
    method: 'get',
    params: data,
    baseURL: 'http://127.0.0.1:3001'
  })
}
// 获取比特浏览器账户
export function browserList(data) {
  return request2({
    url: '/browser/list',
    method: 'post',
    data,
    baseURL: 'http://127.0.0.1:54345'
  })
}
// 下载文件路径
export function path(query) {
  return request2({
    url: '/path',
    method: 'get',
    params: query,
    baseURL: 'http://127.0.0.1:3001'
  })
}
// 删除文件
export function unlink(query) {
  return request2({
    url: '/unlink',
    method: 'get',
    params: query,
    baseURL: 'http://127.0.0.1:3001'
  })
}
// 下载文章文件到本地
export function download(query) {
  return request2({
    url: '/h',
    method: 'get',
    params: query,
    baseURL: 'http://127.0.0.1:3001'
  })
}
// 文章绑定比特浏览器
export function btid(data) {
  // data = objectToFormData(data)
  return request({
    url: '/btid',
    method: 'post',
    data: JSON.stringify(data),
    headers:
    {
      'Content-Type': 'application/json'
    }
  })
}
// 删除文章
export function scwz(data) {
  // data = objectToFormData(data)
  return request({
    url: '/scwz',
    method: 'post',
    data: JSON.stringify(data),
    headers:
    {
      'Content-Type': 'application/json'
    }
  })
}

export function fetchList(query) {
  return request({
    url: '/vue-element-admin/article/list',
    method: 'get',
    params: query
  })
}

export function fetchArticle(id) {
  return request({
    url: '/vue-element-admin/article/detail',
    method: 'get',
    params: { id }
  })
}

export function fetchPv(pv) {
  return request({
    url: '/vue-element-admin/article/pv',
    method: 'get',
    params: { pv }
  })
}

export function createArticle(data) {
  return request({
    url: '/vue-element-admin/article/create',
    method: 'post',
    data
  })
}

export function updateArticle(data) {
  return request({
    url: '/vue-element-admin/article/update',
    method: 'post',
    data
  })
}
